import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

// import { h } from 'vue';
import { DictEnum } from '@vben/constants';
import { VbenIcon } from '@vben/icons';

// import { SafetyCertificateTwoTone } from '@ant-design/icons-vue';
import { Tooltip } from 'ant-design-vue';

// import { getPopupContainer } from '@vben/utils';
import ColorTagToggleList from '#/components/tag/src/color-tag-toggle-list.vue';
import { SensitiveText } from '#/components/text';
import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'name',
    label: '姓名',
  },
  // {
  //   component: 'Input',
  //   fieldName: 'companyId',
  //   fieldName: 'companyName',
  //   label: '公司',
  // },
];

export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: '姓名',
    field: 'name',
    width: 100,
    slots: {
      default: ({ row }) => {
        return (
          <div class="flex items-center justify-center gap-1">
            <span>{row.name}</span>
            {row?.addWechat === 1 ? (
              <div class="inline-block">
                <Tooltip title="已加企微">
                  <VbenIcon class="text-[#0068f4]" icon="tdesign:logo-wecom" />
                </Tooltip>
              </div>
            ) : (
              ''
            )}
            {row?.wechatNo ? (
              <div class="inline-block">
                <Tooltip title="有微信号">
                  <VbenIcon
                    class="text-[#07c160]"
                    icon="streamline-logos:wechat-logo-block"
                  />
                </Tooltip>
              </div>
            ) : (
              ''
            )}
          </div>
        );
      },
    },
  },
  {
    title: '企业名称',
    field: 'companyName',
    minWidth: 280,
  },
  {
    title: '部门',
    field: 'departmentId',
    width: 200,
    slots: {
      default: ({ row }) => {
        return renderDict(row.departmentId, DictEnum.AUDIENCE_DEPARTMENT);
      },
    },
  },
  {
    title: '职位',
    field: 'positionId',
    width: 100,
    slots: {
      default: ({ row }) => {
        return renderDict(row.positionId, DictEnum.AUDIENCE_POSITION);
      },
    },
  },
  {
    title: '手机',
    field: 'mobile',
    width: 160,
    slots: {
      default: ({ row }) => {
        return (
          <SensitiveText
            access-page={1}
            employee-id={row.id}
            text={row.mobile}
            type={1}
          />
        );
      },
    },
  },
  {
    title: '人员标签',
    field: 'labels',
    minWidth: 300,
    slots: {
      default: ({ row }) => {
        return <ColorTagToggleList labels={row.labels} />;
      },
    },
  },
  {
    title: '所在地区',
    field: 'provinceName',
    width: 180,
    slots: {
      default: ({ row }) => {
        if (row?.countryCode !== '00') {
          return <span>{row.countryCode}</span>;
        }

        if (row?.cityName) {
          return (
            <span>
              {row.provinceName}
              {row.cityName}
            </span>
          );
        }

        return <span>{row?.provinceName}</span>;
      },
    },
  },
  {
    title: '跟进人',
    field: 'followUpName',
    width: 100,
    visible: false,
  },
  {
    title: '所属来源',
    field: 'sourceName',
    width: 180,
    visible: false,
  },
  {
    title: '创建人',
    field: 'createByName',
    width: 140,
    visible: false,
  },
  {
    title: '创建时间',
    field: 'createTime',
    width: 180,
    visible: false,
  },
  {
    title: '最后更新人',
    field: 'updateByName',
    width: 140,
    visible: false,
  },
  {
    title: '最后更新时间',
    field: 'updateTime',
    width: 180,
    visible: false,
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 'auto',
  },
];

export const drawerSchema: FormSchemaGetter = () => [
  {
    label: '人员ID',
    fieldName: 'id',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    label: '姓名',
    fieldName: 'name',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '企业名称',
    fieldName: 'companyId',
    component: 'CompanySearchSelect',
    help: '输入企业名称后将从企业数据库中模糊查询',
    componentProps: {},
    rules: 'required',
  },
  {
    component: 'Select',
    fieldName: 'departmentId',
    componentProps: {
      options: getDictOptions(DictEnum.AUDIENCE_DEPARTMENT, true),
    },
    label: '部门',
    rules: 'selectRequired',
  },
  {
    component: 'Select',
    fieldName: 'positionId',
    componentProps: {
      options: getDictOptions(DictEnum.AUDIENCE_POSITION, true),
    },
    label: '职位',
    rules: 'selectRequired',
  },
  {
    label: '手机号',
    fieldName: 'mobile',
    component: 'Input',
    rules: 'mobileRequired',
  },
  {
    label: '备用手机号',
    fieldName: 'secondMobile',
    component: 'Input',
    rules: 'mobile',
  },
  {
    label: '邮箱',
    fieldName: 'email',
    component: 'Input',
    rules: 'emailRequired',
  },
  {
    label: '微信号',
    fieldName: 'wechatNo',
    component: 'Input',
  },
  {
    label: '所属来源',
    fieldName: 'sourceId',
    component: 'SourceSelect',
    rules: 'required',
  },
  {
    component: 'UserListSelect',
    fieldName: 'followUpId',
    label: '跟进人',
    rules: 'selectRequired',
  },
  {
    component: 'PersonalTagSelect',
    fieldName: 'labelIds',
    label: '人员标签',
    defaultValue: [],
    help: '可多选，通过筛选批量设置人员标签',
    rules: 'selectRequired',
  },
  {
    component: 'AddressCascader',
    fieldName: 'addressMap',
    label: '所在地区',
    defaultValue: [],
    rules: 'selectRequired',
  },
  {
    label: '详细地址',
    fieldName: 'address',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '备注',
    fieldName: 'remark',
    component: 'Textarea',
    componentProps: {
      showCount: true,
      maxlength: 100,
    },
  },
];

// 转移跟进人
export const transferSchema: FormSchemaGetter = () => [
  {
    label: '人员IDS',
    fieldName: 'ids',
    component: 'Select',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
    rules: 'selectRequired',
  },
  {
    component: 'UserListSelect',
    fieldName: 'followUpId',
    label: '跟进人',
    rules: 'selectRequired',
  },
];
